package com.anyou.mall.platform.service.impl;

import java.math.BigDecimal;
import java.util.List;
import com.anyou.common.utils.DateUtils;
import com.anyou.mall.platform.domain.PlaPlatformSettings;
import com.anyou.mall.platform.mapper.PlaPlatformSettingsMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.anyou.mall.platform.mapper.OrdDeliveryMapper;
import com.anyou.mall.platform.domain.OrdDelivery;
import com.anyou.mall.platform.service.IOrdDeliveryService;

/**
 * 配送设置Service业务层处理
 *
 * @author ruoyi
 * @date 2023-10-10
 */
@Service
public class OrdDeliveryServiceImpl  extends ServiceImpl<OrdDeliveryMapper, OrdDelivery> implements IOrdDeliveryService
{
    @Autowired
    private OrdDeliveryMapper ordDeliveryMapper;

    /**
     * 查询配送设置
     *
     * @return 配送设置
     */
    @Override
    public OrdDelivery selectOrdDeliveryByDeliveryId()
    {
        List<OrdDelivery> ordDeliveries = ordDeliveryMapper.selectList(new LambdaQueryWrapper<OrdDelivery>()
                .last("limit 1"));
        if (!ordDeliveries.isEmpty()){
            return ordDeliveries.get(0);
        }
        /*OrdDelivery ordDelivery = new OrdDelivery();
        ordDelivery.setElevatorDeliveryPrice(BigDecimal.valueOf(0.00));
        ordDelivery.setStairsDeliveryPrice(BigDecimal.valueOf(0.00));
        ordDelivery.setBucketDetainPrice(BigDecimal.valueOf(0.00));
        ordDelivery.setStreetDeliveryPrice(BigDecimal.valueOf(0.00));
        ordDelivery.setStandardDeliveryPrice(BigDecimal.valueOf(0.00));*/
        return null;
    }

    /**
     * 查询配送设置列表
     *
     * @param ordDelivery 配送设置
     * @return 配送设置
     */
    @Override
    public List<OrdDelivery> selectOrdDeliveryList(OrdDelivery ordDelivery)
    {
        return ordDeliveryMapper.selectOrdDeliveryList(ordDelivery);
    }

    /**
     * 新增配送设置
     *
     * @param ordDelivery 配送设置
     * @return 结果
     */
    @Override
    public int insertOrdDelivery(OrdDelivery ordDelivery)
    {
        ordDelivery.setCreateTime(DateUtils.getNowDate());
        return ordDeliveryMapper.insertOrdDelivery(ordDelivery);
    }

    /**
     * 修改配送设置
     *
     * @param ordDelivery 配送设置
     * @return 结果
     */
    @Override
    public int updateOrdDelivery(OrdDelivery ordDelivery)
    {
        if (ordDelivery.getDeliveryId()==null){
            List<OrdDelivery> ordDeliveries = ordDeliveryMapper.selectList(new LambdaQueryWrapper<OrdDelivery>()
                    .last("limit 1"));
            if (ordDeliveries.isEmpty()){
                ordDelivery.setCreateTime(DateUtils.getNowDate());
                int insert = ordDeliveryMapper.insert(ordDelivery);
                return insert;
            }
        }else {
            ordDelivery.setUpdateTime(DateUtils.getNowDate());
            int update = ordDeliveryMapper.updateById(ordDelivery);
            return update;
        }
        throw new RuntimeException("操作失败");
    }

    /**
     * 批量删除配送设置
     *
     * @param deliveryIds 需要删除的配送设置主键
     * @return 结果
     */
    @Override
    public int deleteOrdDeliveryByDeliveryIds(Long[] deliveryIds)
    {
        return ordDeliveryMapper.deleteOrdDeliveryByDeliveryIds(deliveryIds);
    }

    /**
     * 删除配送设置信息
     *
     * @param deliveryId 配送设置主键
     * @return 结果
     */
    @Override
    public int deleteOrdDeliveryByDeliveryId(Long deliveryId)
    {
        return ordDeliveryMapper.deleteOrdDeliveryByDeliveryId(deliveryId);
    }
}
